package org.linlinjava.litemall.admin.controller;

import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.constant.LitemallAdminConstants;
import org.linlinjava.litemall.admin.service.AdminSubscribeService;
import org.linlinjava.litemall.admin.vo.subscribe.AdminSpecificationsRespVO;
import org.linlinjava.litemall.core.notify.AwsNotifyService;
import org.linlinjava.litemall.core.notify.NoticeHelper;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.beans.Constants;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.dto.LumiereRulesDto;
import org.linlinjava.litemall.db.dto.LumiereSpecificDto;
import org.linlinjava.litemall.db.dto.LumiereSubscribeDto;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.BeanUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import static org.linlinjava.litemall.admin.util.AdminResponseCode.MOBILE_CODE_ONE;

/**
 * 管理卢米埃订阅控制器
 *
 * @author yliyun
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/admin/lumiere/subscribe")
@Validated
public class AdminLumiereSubscribeController {
    /**
     * 卢米埃订阅服务
     */
    @Autowired
    private LumiereSubscribeService lumiereSubscribeService;

    /**
     * 卢米埃订阅规则服务
     */
    @Autowired
    private LumiereSubscribeRuleService lumiereSubscribeRuleService;

    /**
     * litemall店地区服务
     */
    @Autowired
    private LitemallShopRegionService litemallShopRegionService;

    /**
     * litemall商品服务
     */
    @Autowired
    private LitemallGoodsService litemallGoodsService;

    /**
     * 卢米埃subscirbe商品服务
     */
    @Autowired
    private LumiereSubscirbeGoodsService lumiereSubscirbeGoodsService;

    /**
     * litemall商品规范服务
     */
    @Autowired
    private LitemallGoodsSpecificationService litemallGoodsSpecificationService;

    /**
     * 商品配方关联表
     */
    @Autowired
    private LumiereGoodsFormulaCorrelationService lumiereGoodsFormulaCorrelationService;

    @Autowired
    private LumiereFormulaService lumiereFormulaService;

    @Autowired
    private LumiereFormulaMaterialService lumiereFormulaMaterialService;

    @Autowired
    private LumiereFormulaSpecificationsService lumiereFormulaSpecificationsService;

    @Autowired
    private LumiereFormulaSpecificationsDataProportioningService lumiereFormulaSpecificationsDataProportioningService;

    /**
     * 卢米埃订阅用户服务
     */
    @Autowired
    private LumiereSubscribeUserService lumiereSubscribeUserService;

    @Autowired
    private NoticeHelper noticeHelper;

    /**
     * aws通知服务
     */
    @Autowired
    private AwsNotifyService awsNotifyService;

    @Autowired
    private LitemallUserService litemallUserService;

    /**
     * 管理订阅服务
     */
    @Autowired
    private AdminSubscribeService adminSubscribeService;


    /**
     * 列表
     *
     * @param key      关键
     * @param name     名字
     * @param page     页面
     * @param limit    限制
     * @param status   状态
     * @param useRange 使用范围
     * @param sort     排序
     * @param order    订单
     * @return {@link Object}
     */
    @GetMapping("/list")
    @LogAnno
    public Object list(String key, String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       Integer status,Byte useRange,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        IPage<LumiereSubscribe> lumiereSubscribes = lumiereSubscribeService.querySelective(name, page, status,useRange, limit, sort, order);
        List<LumiereSubscribeDto> dtos = new ArrayList<>();
        dtos = lumiereSubscribes.getRecords().stream().map(subcribe -> {
            Integer id = subcribe.getId();
            List<LumiereSubscribeRule> rules = lumiereSubscribeRuleService.querySubscribeRule(id);

            LumiereSubscribeDto dto = new LumiereSubscribeDto();
            dto.setRules(rules);
            BeanUtils.copyProperties(subcribe, dto);
            if(subcribe.getAutoSub() == true){
                dto.setAutoSub((byte) 1);
            }else{
                dto.setAutoSub((byte) 0);
            }
            return dto;
        }).collect(Collectors.toList());
        return ResponseUtil.okPage(lumiereSubscribes,dtos);
    }

    /**
     * 列表商品打折
     *
     * @return {@link Object}
     */
    @GetMapping("/listGoodsOnSale")
    @LogAnno
    public Object listGoodsOnSale() {
        //查询总店中的所有上架商品
        List<LitemallGoods> goods = litemallGoodsService.queryPutOnSale(null);
        return ResponseUtil.okList(goods);
    }

    /**
     * 规范列表
     *
     * @param goodsId 商品id
     * @return {@link Object}
     *///    listSpecification
    @GetMapping("/listSpecifications")
    @LogAnno
    public Object listSpecifications(@RequestParam(value = "goodsId") Integer goodsId) {
        LumiereGoodsFormulaCorrelation goodsFormula = lumiereGoodsFormulaCorrelationService.getGoodsFormulaByGoodsId(goodsId);
        if(goodsFormula == null){
            return ResponseUtil.okList(new ArrayList<>());
        }
        List<LumiereFormulaSpecifications> formulaSpecificationsList = lumiereFormulaSpecificationsService.selectListByFormulaId(goodsFormula.getFormulaId());
        List<AdminSpecificationsRespVO> list = CollStreamUtil.toList(formulaSpecificationsList,
                formulaSpecifications->new AdminSpecificationsRespVO().setId(formulaSpecifications.getId()).setSpecification(formulaSpecifications.getSpecificationsName()).setPrice(formulaSpecifications.getSpecificationsPrice()));
        return ResponseUtil.okList(list);
    }

    /**
     * 创建订阅
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PostMapping("/createSubscribe")
    @LogAnno
    @Transactional
    public Object createSubscribe(@RequestBody LumiereSubscribeDto dto) {

        //插入订阅配置
        LumiereSubscribe lumiereSubscribe = new LumiereSubscribe();
        if(dto.getAutoSub() == 0){
            lumiereSubscribe.setAutoSub(false);
        }else{
            lumiereSubscribe.setAutoSub(true);
        }
        BeanUtils.copyProperties(dto, lumiereSubscribe);

        //可订阅门店，配送时间段，订阅图片
        String timeRange = dto.getDistributionStartTime() + "--" + dto.getDistributionEndTime();

//        String shopIds = "";
        if (dto.getRegions().size() != 0) {
            List<LitemallShopRegion> regions = litemallShopRegionService.queryByRegionIds(dto.getRegions());
            Integer[] shopIds = new Integer[regions.size()];
            if (dto.getAreaLimit() == 0) {
                lumiereSubscribe.setShopIds(null);
            } else {
                for (int i = 0; i < regions.size(); i++) {
                    shopIds[i] = regions.get(i).getShopId();
                }
            }
            Integer[] regionIds =  dto.getRegions().toArray(new Integer[dto.getRegions().size()]);
            lumiereSubscribe.setRegionIds(regionIds);
            lumiereSubscribe.setShopIds(shopIds);
        }
        lumiereSubscribe.setTimeRanges(timeRange);


        //rule表数据
        LumiereSubscribeRule weekRule = new LumiereSubscribeRule();
        LumiereSubscribeRule monthRule = new LumiereSubscribeRule();
        LumiereSubscribeRule yearRule = new LumiereSubscribeRule();

        //goods表数据
        List<LumiereSubscribeGoods> goods = new ArrayList<>();

        goods = dto.getSubscribeSpecifications().stream().map(specifications -> {
            LumiereSubscribeGoods good = new LumiereSubscribeGoods();
            BeanUtils.copyProperties(specifications, good);
            good.setSpecificationIds(specifications.getSpecificationIds());
            return good;
        }).collect(Collectors.toList());

        //插入数据
        lumiereSubscribe.setStatus(2);
        lumiereSubscribe.setAddTime(LocalDateTime.now());
        lumiereSubscribeService.add(lumiereSubscribe);
        Integer primaryKey = lumiereSubscribe.getId();

        goods.stream().forEach(good -> {
            good.setSubscribeId(primaryKey);
            lumiereSubscirbeGoodsService.add(good);
        });


        if (dto.getWeekType() != null && dto.getWeekType() != false) {

            BeanUtils.copyProperties(dto.getWeekRule(), weekRule);
            weekRule.setSubscribeId(primaryKey);
            weekRule.setRuleType((byte) 1);
            weekRule.setDaysTimes(weekRule.getDaysTimes() == null ? 0 : weekRule.getDaysTimes());
            weekRule.andLogicalDeleted(false);
            weekRule.setStatus(1);
            weekRule.setDeleted(false);
            weekRule.setAddTime(LocalDateTime.now());
            weekRule.setUpdateTime(LocalDateTime.now());
            lumiereSubscribeRuleService.add(weekRule);
        }

        if (dto.getMonthType() != null && dto.getMonthType() != false) {
            BeanUtils.copyProperties(dto.getMonthRule(), monthRule);
            monthRule.setRuleType((byte) 2);
            monthRule.setSubscribeId(primaryKey);
            monthRule.setDaysTimes(monthRule.getDaysTimes() == null ? 0 : monthRule.getDaysTimes());
            monthRule.andLogicalDeleted(false);
            monthRule.setStatus(1);
            monthRule.setDeleted(false);
            monthRule.setAddTime(LocalDateTime.now());
            monthRule.setUpdateTime(LocalDateTime.now());
            lumiereSubscribeRuleService.add(monthRule);
        }

        if (dto.getYearType() != null && dto.getYearType() != false) {
            BeanUtils.copyProperties(dto.getYearRule(), yearRule);
            yearRule.setRuleType((byte) 3);
            yearRule.setSubscribeId(primaryKey);
            yearRule.setDaysTimes(yearRule.getDaysTimes() == null ? 0 : yearRule.getDaysTimes());
            yearRule.andLogicalDeleted(false);
            yearRule.setStatus(1);
            yearRule.setDeleted(false);
            yearRule.setAddTime(LocalDateTime.now());
            yearRule.setUpdateTime(LocalDateTime.now());
            lumiereSubscribeRuleService.add(yearRule);
        }


        return ResponseUtil.ok();
    }

    /**
     * 更新订阅
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PostMapping("/updateSubscribe")
    @LogAnno
    @Transactional
    public Object updateSubscribe(@RequestBody LumiereSubscribeDto dto) {

        //如果已经有用户订阅了该订阅，则该订阅不允许被修改
        Integer count =  lumiereSubscribeUserService.querySubscribeUserById(dto.getId()).intValue();
        if(count > 0){
            return ResponseUtil.fail(111,"修改失败,该订阅已经有用户使用");
        }

        //插入订阅配置
        LumiereSubscribe lumiereSubscribe = new LumiereSubscribe();
        BeanUtils.copyProperties(dto, lumiereSubscribe);

        //可订阅门店，配送时间段，订阅图片
        String timeRange = dto.getDistributionStartTime() + "--" + dto.getDistributionEndTime();

        if(dto.getRegions().size() != 0) {
            List<LitemallShopRegion> regions = litemallShopRegionService.queryByRegionIds(dto.getRegions());
            Integer[] shopIds = new Integer[regions.size()];
            if (dto.getAreaLimit() == 0) {
                lumiereSubscribe.setShopIds(null);
            } else {
                for (int i = 0; i < regions.size(); i++) {
                    shopIds[i] = regions.get(i).getShopId();
                }
            }
            Integer[] regionIds =  dto.getRegions().toArray(new Integer[dto.getRegions().size()]);
            if(dto.getAreaLimit() == 0){
                lumiereSubscribe.setRegionIds(null);
                lumiereSubscribe.setShopIds(null);
            }else{

                lumiereSubscribe.setRegionIds(regionIds);
                lumiereSubscribe.setShopIds(shopIds);
            }
        }else{
            lumiereSubscribe.setRegionIds(null);
            lumiereSubscribe.setShopIds(null);
        }
//        lumiereSubscribe.se
        lumiereSubscribe.setTimeRanges(timeRange);
        if(dto.getAutoSub() == 0){
            lumiereSubscribe.setAutoSub(false);
        }else{
            lumiereSubscribe.setAutoSub(true);
        }

        //rule表数据
        LumiereSubscribeRule weekRule = new LumiereSubscribeRule();
        LumiereSubscribeRule monthRule = new LumiereSubscribeRule();
        LumiereSubscribeRule yearRule = new LumiereSubscribeRule();

        //goods表数据
        List<LumiereSubscribeGoods> goods = dto.getSubscribeSpecifications().stream().map(specifications -> {
            LumiereSubscribeGoods good = new LumiereSubscribeGoods();
            BeanUtils.copyProperties(specifications, good);
            good.setSpecificationIds(specifications.getSpecificationIds());
            return good;
        }).collect(Collectors.toList());

        //插入数据
//        lumiereSubscribe.setStatus(2);
        lumiereSubscribeService.update(lumiereSubscribe);
        Integer primaryKey = lumiereSubscribe.getId();


        lumiereSubscirbeGoodsService.deleteBySubscribeId(primaryKey);
        goods.stream().forEach(good -> {
            good.setSubscribeId(primaryKey);
            good.setDeleted(false);
            lumiereSubscirbeGoodsService.add(good);
        });


        if (dto.getWeekType() != null) {
            BeanUtils.copyProperties(dto.getWeekRule(), weekRule);
            weekRule.setSubscribeId(primaryKey);
            weekRule.setRuleType((byte) 1);
            weekRule.setDeleted(false);
            weekRule.setAddTime(LocalDateTime.now());
            weekRule.setUpdateTime(LocalDateTime.now());
            //查询规则是否存在，不存在就增加，否则更新(通过subscribeId和type查询rule)
            LumiereSubscribeRule rule = lumiereSubscribeRuleService.queryOne(dto.getId(), 1);
            weekRule.setStatus(dto.getWeekType() == false ? 0 : 1);
            if (rule == null ) {
               if(dto.getWeekType() ==true){
                   lumiereSubscribeRuleService.add(weekRule);
               }

            }else{
                weekRule.setId(rule.getId());
                lumiereSubscribeRuleService.update(weekRule);
            }
        }

        if (dto.getMonthType() != null) {
            BeanUtils.copyProperties(dto.getMonthRule(), monthRule);
            monthRule.setRuleType((byte) 2);
            monthRule.setSubscribeId(primaryKey);
            //查询规则是否存在，不存在就增加，否则更新(通过subscribeId和type查询rule)
            LumiereSubscribeRule rule = lumiereSubscribeRuleService.queryOne(dto.getId(), 2);
            monthRule.setStatus(dto.getMonthType() == false ? 0 : 1);
            monthRule.setDeleted(false);
            monthRule.setAddTime(LocalDateTime.now());
            monthRule.setUpdateTime(LocalDateTime.now());
            if (rule == null) {
                if(dto.getMonthType() == true){
                    lumiereSubscribeRuleService.add(monthRule);
                }
            }else{
                monthRule.setId(rule.getId());
                lumiereSubscribeRuleService.update(monthRule);
            }
        }

        if (dto.getYearType() != null) {
            BeanUtils.copyProperties(dto.getYearRule(), yearRule);
            yearRule.setRuleType((byte) 3);
            yearRule.setSubscribeId(primaryKey);

            yearRule.setDeleted(false);
            yearRule.setAddTime(LocalDateTime.now());
            yearRule.setUpdateTime(LocalDateTime.now());
            //查询规则是否存在，不存在就增加，否则更新(通过subscribeId和type查询rule)
            LumiereSubscribeRule rule = lumiereSubscribeRuleService.queryOne(dto.getId(), 3);
            yearRule.setStatus(dto.getYearType() == false ? 0 : 1);
            if (rule == null) {
               if(dto.getYearType() == true){
                   lumiereSubscribeRuleService.add(yearRule);
               }
            }else{
                yearRule.setId(rule.getId());
                lumiereSubscribeRuleService.update(yearRule);
            }
        }

        return ResponseUtil.ok();
    }

    /**
     * 订阅列表详细
     *
     * @param subscribeId 订阅id
     * @return {@link Object}
     */
    @GetMapping("/listSubscribeDetail")
    @LogAnno
    public Object listSubscribeDetail(Integer subscribeId) {
        LumiereSubscribe lumiereSubscribe = lumiereSubscribeService.querySubscribeById(subscribeId);
        LumiereSubscribeDto dto = new LumiereSubscribeDto();
        BeanUtils.copyProperties(lumiereSubscribe, dto);
        if (lumiereSubscribe.getAutoSub() == false) {
            dto.setAutoSub((byte) 0);
        } else {
            dto.setAutoSub((byte) 1);
        }

        if (lumiereSubscribe.getShopIds() == null) {
            dto.setAreaLimit((byte) 0);
        } else {
            dto.setAreaLimit((byte) 1);
        }

        //订阅对应的规则
        List<LumiereSubscribeRule> rules = lumiereSubscribeRuleService.querySubscribeRule(subscribeId);
        //遍历查询的rule，设置weekType,monthType,yearType三种规则的设置状态
        rules.stream().forEach(rule -> {
            if (rule.getRuleType() == 1 && rule.getStatus() == 1) {
                dto.setWeekType(true);
                LumiereRulesDto weekDto = new LumiereRulesDto();
                BeanUtils.copyProperties(rule, weekDto);
                configRuleType(rule, weekDto);
                dto.setWeekRule(weekDto);
            }

            if (rule.getRuleType() == 2 && rule.getStatus() == 1) {
                dto.setMonthType(true);
                LumiereRulesDto monthDto = new LumiereRulesDto();
                BeanUtils.copyProperties(rule, monthDto);
                configRuleType(rule, monthDto);
                dto.setMonthRule(monthDto);
            }

            if (rule.getRuleType() == 3 && rule.getStatus() == 1) {
                dto.setYearType(true);
                LumiereRulesDto yearDto = new LumiereRulesDto();
                BeanUtils.copyProperties(rule, yearDto);
                configRuleType(rule, yearDto);
                dto.setYearRule(yearDto);
            }
        });

        //如果周，月，年的其中一个配置为空，则手动给予默认值
        if (dto.getWeekType() == null || dto.getWeekType() == false) {
            dto.setWeekType(false);
            LumiereRulesDto weekDto = new LumiereRulesDto();
            dto.setWeekRule(weekDto);
        }

        if (dto.getMonthType() == null || dto.getMonthType() == false) {
            dto.setMonthType(false);
            LumiereRulesDto monthDto = new LumiereRulesDto();
            dto.setMonthRule(monthDto);
        }

        if (dto.getYearType() == null || dto.getYearType() == false) {
            dto.setYearType(false);
            LumiereRulesDto yearDto = new LumiereRulesDto();
            dto.setYearRule(yearDto);
        }

        //订阅对应的商品
        List<LumiereSubscribeGoods> goods = lumiereSubscirbeGoodsService.queryLumiereSubscribeById(subscribeId);
        List<LumiereSpecificDto> specificDtos = new ArrayList<>();
        goods.stream().forEach(good -> {
            //商品名
            String goodsName = litemallGoodsService.findById(good.getGoodsId()).getName();

            //规格名
            String specificName = litemallGoodsSpecificationService.findById(Integer.valueOf(good.getSpecificationIds()[0])).getSpecification();

            LumiereSpecificDto specificDto = new LumiereSpecificDto();
            BeanUtils.copyProperties(good, specificDto);
            specificDto.setSelectGoodsValue(goodsName);
            specificDto.setSelectSpecificationValue(specificName);
            specificDtos.add(specificDto);
        });
        dto.setSubscribeSpecifications(specificDtos);

        List<Integer> regions = new ArrayList<>();
        if(lumiereSubscribe.getRegionIds() != null){
            regions = Arrays.asList(lumiereSubscribe.getRegionIds());
        }
        dto.setRegions(regions);
        return ResponseUtil.ok(dto);
    }

    /**
     * 删除
     *
     * @param lumiereSubscribe 卢米埃订阅
     * @return {@link Object}
     */
    @PostMapping("/delete")
    @LogAnno
    public Object delete(@RequestBody LumiereSubscribe lumiereSubscribe) {
        lumiereSubscribeService.deleteById(lumiereSubscribe.getId());
        return ResponseUtil.ok();
    }

//    changeSubscribeStatus

    /**
     * 改变订阅状态
     *
     * @param id id
     * @return {@link Object}
     */
    @PostMapping("/changeSubscribeStatus")
    @LogAnno
    public Object changeSubscribeStatus(@NotNull @RequestParam(value = "id") Integer id) {
        LumiereSubscribe subscribe = new LumiereSubscribe();
        subscribe.setId(id);
        int status = 0;
       /* Integer sum = (int) lumiereSubscribeUserService.querySubscribeId(id);

        if(sum > 0){
            return ResponseUtil.fail(111,"已存在用户拥有该订阅");
        }*/
        LumiereSubscribe lumiereSubscribe = lumiereSubscribeService.findById(id);
        if (lumiereSubscribe.getStatus() == 0) {
            status = 1;
            subscribe.setStartTime(LocalDateTime.now());
            subscribe.setEndTime(null);
        } else if (lumiereSubscribe.getStatus() == 1) {
            Integer count = adminSubscribeService.queryUserTotal(null, null, null, id);
            if(count > 0){
                return ResponseUtil.fail(555,"还有在使用订阅的人数，不能修改");
            }
            status = 0;
            subscribe.setEndTime(LocalDateTime.now());
            subscribe.setStartTime(null);
        } else if (lumiereSubscribe.getStatus() == 2) {
            status = 1;
            subscribe.setStartTime(LocalDateTime.now());
            subscribe.setEndTime(null);
        }
        subscribe.setStatus(status);
        lumiereSubscribeService.update(subscribe);
        if(status!=0){return ResponseUtil.ok();}

        //推送订阅下架 系统消息
        List<LumiereSubscribeUser> lumiereSubscribeUsers = lumiereSubscribeUserService.list(Wrappers.lambdaQuery(LumiereSubscribeUser.class)
                .eq(LumiereSubscribeUser::getSubscribeId,lumiereSubscribe.getId())
        );
        List<Integer> collect = lumiereSubscribeUsers.stream().map(LumiereSubscribeUser::getUserId).distinct().collect(Collectors.toList());
        CompletableFuture.runAsync(()->{
            collect.stream().forEach(userId->{
                if(userId==null){return;}
                LitemallUser litemallUser = litemallUserService.findById(userId);
                //系统消息
                noticeHelper.noticeUser(Constants.MSG_TYPE_PROMOTION, LitemallAdminConstants.ADMIN_SUBSCRIPTION_TITLE,
                        String.format(LitemallAdminConstants.ADMIN_SUBSCRIPTION_USER_NOTICEHELPER,lumiereSubscribe.getName()),userId,lumiereSubscribe);
                //短信消息
                if(StrUtil.isNotBlank(litemallUser.getMobile())){
                    awsNotifyService.sendSms(MOBILE_CODE_ONE +litemallUser.getMobile(),
                            String.format(LitemallAdminConstants.ADMIN_SUBSCRIPTION_USER_NOTICEHELPER,lumiereSubscribe.getName()),
                            Constants.AWS_MESSAGE_TYPE_PROMOTIONAL);
                }
                //邮箱消息
                if(StrUtil.isNotBlank(litemallUser.getEmail())){
                    awsNotifyService.noticeMail(LitemallAdminConstants.ADMIN_SUBSCRIPTION_TITLE,
                            String.format(LitemallAdminConstants.ADMIN_SUBSCRIPTION_USER_NOTICEHELPER,lumiereSubscribe.getName()),
                            String.format(LitemallAdminConstants.ADMIN_SUBSCRIPTION_USER_NOTICEHELPER,lumiereSubscribe.getName()),
                            litemallUser.getEmail());
                }
            });
        });
        return ResponseUtil.ok();
    }

    /**
     *
     * 配置规则类型
     *
     * @param rule     规则
     * @param rulesDto 规则dto
     */
    public void configRuleType(LumiereSubscribeRule rule, LumiereRulesDto rulesDto) {
        if (rule.getDaysTimes() != null && rule.getDaysTimes()!=0) {
            rulesDto.setType((byte) 1);
        }

        if (rule.getWeekTimes() != null && rule.getWeekTimes() != 0) {
            rulesDto.setType((byte) 2);
        }

        if (rule.getMonthTimes() != null && rule.getMonthTimes() != 0) {
            rulesDto.setType((byte) 3);
        }

        if (rule.getYearTimes() != null && rule.getYearTimes() != 0) {
            rulesDto.setType((byte) 4);
        }
    }

    /**
     * 查询所有推
     * 查询所有已启用的订阅
     *
     * @return {@link Object}
     */
    @GetMapping("queryAllPushed")
    @LogAnno
    public Object queryAllPushed(){
       return ResponseUtil.okList(lumiereSubscribeService.queryAllPushed());
    }
}
